package com.macro.mall.portal.runner;

import com.macro.mall.mapper.SmsFlashPromotionSkuRelationMapper;
import com.macro.mall.model.SmsFlashPromotionSkuRelation;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PanicBuyingTimer {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private SmsFlashPromotionSkuRelationMapper mapper;
//    @Autowired
//    private Redisson
    /**
     * 商品预热
     */
    @Scheduled(cron = "0 0 22 * * ?")
    public void panicBuyingTimer() {

        List<SmsFlashPromotionSkuRelation> list = mapper.productSkuRelation();
        list.forEach(p->{
            String Key = p.getFlashPromotionId()+":"+ p.getFlashPromotionSessionId()+":"+p.getSkuId();
            stringRedisTemplate.opsForValue().set(Key,String.valueOf(p.getFlashPromotionCount()));
        });

    }

    @PostConstruct
    public void init() {
        panicBuyingTimer();
    }



}
